package practice1_100;

public class Practice1143 {
    public int longestCommonSubsequence(String text1, String text2) {
        char[] text1char=text1.toCharArray();
        char[] text2char=text2.toCharArray();
        int lenT1=text1.length();
        int lenT2=text2.length();
        int[][] dpTable=new int[lenT1+1][lenT2+1];
        int temp=Integer.MIN_VALUE;
        for (int i = 1; i < lenT1+1; i++) {
            for (int j = 1; j < lenT2+1; j++) {
                if(text1char[i-1]==text2char[j-1])dpTable[i][j]=dpTable[i-1][j-1]+1;
                else dpTable[i][j]=Math.max(dpTable[i-1][j],dpTable[i][j-1]);
                temp =dpTable[i][j]>temp?dpTable[i][j]:temp;
            }
        }
        return temp;
    }

    public static void main(String[] args) {
       int c= new Practice1143().longestCommonSubsequence("abcfsafhglfsdjgldfkjgldfkabcdef","defalkgjdlfkgjlskjglabcdef");
        System.out.println(c);
    }
}
